// Copyright 2011-2012, Vanya Davidenko.
// Используемая кодировка: UTF-8.

#ifndef LIBV_SFILE_H_
#define LIBV_SFILE_H_

#ifdef _WIN32
# include <libv/windows_lean.h>
#endif

#include <string>
#include <libv/stdint.h>
#include <libv/file/basic_file.h>



namespace libv
{

class SFile : public BasicFile
{
  public:
    typedef BasicFile::OpenType OpenType;
    typedef BasicFile::LockType LockType;
    typedef BasicFile::PreallocType PreallocType;
    typedef BasicFile::Prealloc Prealloc;

    inline bool Open(const ::std::string& file_path,
                     const int open_type,
                     const bool enable_read_ahead_caching = true);


    inline bool Open(const ::std::string& file_path,
                     const int open_type,
                     const bool enable_read_ahead_caching = true) const;


    inline bool Write(const fpos64& offset,
                      const void* data,
                      const uint32_t data_size);


    inline bool Read(const fpos64& offset,
                     void* buffer,
                     const uint32_t buffer_size) const;

  private:
    inline bool WriteImpl(const fpos64& offset,
                          const void* data,
                          const uint32_t data_size);

    inline bool ReadImpl(const fpos64& offset,
                         void* buffer,
                         const uint32_t buffer_size) const;

#ifdef _WIN32
    inline OVERLAPPED MakeOverlapped(const fpos64 offset) const;
#endif
};

}  // libv


#include <libv/file/sfile.hpp>
#if defined(_WIN32)
# include <libv/file/windows/sfile_impl.hpp>
#elif defined(__linux__)
# include <libv/file/linux/sfile_impl.hpp>
#else
# error "This header should be used in Windows or Linux 2.6+."
#endif

#endif  // LIBV_SFILE_H_
